package com.ggh.jinjilive.ui.mine;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.BarUtils;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityMineDetailBinding;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.gyf.immersionbar.ImmersionBar;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


@Route(path = ARouterUtils.MineDetailActivity)
public class MineDetailActivity extends BaseActivity<ActivityMineDetailBinding> {
    private String[] mFragmentTitles = {"收到礼物明细", "直播时长明细"};

    //列表榜
    public List<Fragment> fragmentArrayList = new ArrayList<>();

    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).keyboardEnable(true).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_mine_detail;
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
        fragmentArrayList.clear();
        //
        fragmentArrayList.add(new MineDetailFragment("收到礼物明细"));
        //
        fragmentArrayList.add(new MineDetailFragment("直播时长明细"));
    }

    @Override
    public void initData() {
        super.initData();

        //适配器
        ProfitOrderAdapter profitOrderAdapter = new ProfitOrderAdapter(getSupportFragmentManager());
        binding.vp.setAdapter(profitOrderAdapter);
        binding.stlOrder.setViewPager(binding.vp, mFragmentTitles);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

    }

    class ProfitOrderAdapter extends FragmentPagerAdapter {

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentArrayList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentArrayList.size();
        }

        @Override
        public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
//            super.destroyItem(container, position, object);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            super.setPrimaryItem(container, position, object);
        }
    }
}
